package com.tkmybatis.hfy.base.entity;

import com.tkmybatis.exception.ErrorType;
import com.tkmybatis.hfy.base.enums.ResultCode;

import java.io.Serializable;


public class Result<T> implements Serializable{
	private static final long serialVersionUID = 1L;
	
	private String ret;
	private String msg;
	private T data;
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public T getData() {
		return data;
	}
	public void setData(T data) {
		this.data = data;
	}
    public String getRet() {
        return ret;
    }
    public void setRet(String ret) {
        this.ret = ret;
    }
    public Result(String ret) {
		this.ret = ret;
	}
	public Result(String ret, String msg) {
		this.ret = ret;
		this.msg = msg;
	}
	public Result(String ret, String msg, T data) {
		this.ret = ret;
		this.msg = msg;
		this.data = data;
	}
	public static Result fail() {
		return new Result(ResultCode.FAIL.getId());
	}
	public static Result fail(String msg) {
		return new Result(ResultCode.FAIL.getId(), msg);
	}
	public static Result fail(String code, String msg) {
		return new Result(code, msg);
	}
	public static Result fail(ResultCode resultCode) {
		return new Result(resultCode.getId(), resultCode.getText());
	}
	public static Result fail(ErrorType errorType) {
		return new Result(errorType.getCode(), errorType.getMsg());
	}
	public static Result sucess() {
		return new Result(ResultCode.SUCCESS.getId(), "成功");
	}
	public static <T> Result<T> sucess(T data) {
		return new Result(ResultCode.SUCCESS.getId(), "成功", data);
	}
	
	public Result() {}
}
